#include "testApp.h"

//--------------------------------------------------------------
void testApp::setup(){
	ofSetWindowTitle("Pixelator Example by Pat Long (plong0)");
	ofBackground(185, 113, 0);
	ofSetFrameRate(60);
	
	videoWidth = 640;
	videoHeight = 480;
	
	videoInput.setVerbose(true);
	videoInput.initGrabber(videoWidth, videoHeight);
	
	pixelWidth = pixelHeight = 16;
	pixelator.setPixelSize(pixelWidth, pixelHeight);
	showPixelated = true;
}

//--------------------------------------------------------------
void testApp::update(){
	videoInput.grabFrame();
	if(videoInput.isFrameNew()){
		videoOutput.setFromPixels(videoInput.getPixels(), videoWidth, videoHeight, OF_IMAGE_COLOR);
		videoOutput.mirror(true, false);
		pixelator.pixelateImage(&videoOutput);
	}
}

//--------------------------------------------------------------
void testApp::draw(){
	ofSetColor(255, 255, 255);
	if(showPixelated)
		pixelator.drawPixelated(50, 50);
	else
		pixelator.drawOriginal(50, 50);
	
	ofSetColor(0, 255, 0);
	ofNoFill();
	ofRect(50, 50, videoWidth, videoHeight);
	ofFill();
	ofSetColor(255, 255, 255);
}

//--------------------------------------------------------------
void testApp::keyPressed(int key){
}

//--------------------------------------------------------------
void testApp::keyReleased(int key){
	if(key == 'p' || key == 'P')
		showPixelated = !showPixelated;
}

//--------------------------------------------------------------
void testApp::mouseMoved(int x, int y ){

}

//--------------------------------------------------------------
void testApp::mouseDragged(int x, int y, int button){

}

//--------------------------------------------------------------
void testApp::mousePressed(int x, int y, int button){

}

//--------------------------------------------------------------
void testApp::mouseReleased(int x, int y, int button){

}

//--------------------------------------------------------------
void testApp::windowResized(int w, int h){

}

